package com.lanchetech.dao;

import com.lanchetech.bean.request.CountByTimeReq;import com.lanchetech.bean.request.OrderPageReq;import com.lanchetech.bean.request.PageReq;import com.lanchetech.bean.request.TimeRangeReq;import com.lanchetech.bean.response.OrderResp;import com.lanchetech.bean.vo.*;import com.lanchetech.entity.Orders;
import java.math.BigDecimal;import java.util.Collection;import java.util.Date;import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;import org.apache.ibatis.annotations.Select;

@Mapper
public interface OrdersMapper {
    int deleteByPrimaryKey(Long id);

    int insert(Orders record);

    int insertSelective(Orders record);

    Orders selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Orders record);

    int updateByPrimaryKey(Orders record);

    int updateBatch(List<Orders> list);

    int updateBatchSelective(List<Orders> list);

    int batchInsert(@Param("list") List<Orders> list);

    MineStatisticsVO countOrders(@Param("userId") Long userId);

    MineStatisticsVO countOrdersByOrderType(@Param("userId") Long userId, @Param("orderType") Byte orderType);

    List<OrderResp> findAllFrontPage(PageReq req);

    List<OrderResp> findAllBackPage(OrderPageReq req);

    List<OrderResp> findAllByIds(@Param("userId") Long userId, @Param("shopId") Long shopId, @Param("orderIds") List<Long> orderIds);

    int updateHiddenAndUpdatedAtByIdAndUserId(@Param("updatedHidden") Byte updatedHidden, @Param("updatedUpdatedAt") Date updatedUpdatedAt, @Param("id") Long id, @Param("userId") Long userId);

    int updateStatusAndPayTimeByTradeNo(@Param("updatedStatus") Byte updatedStatus, @Param("updatedPayTime") Date updatedPayTime, @Param("tradeNo") String tradeNo);

    Orders findOneByTradeNo(@Param("tradeNo") String tradeNo);

    int updateOrderLogistics(Orders orders);

    int updateRemarkById(Orders orders);

    int updateTotalRefundAmountById(@Param("updatedTotalRefundAmount") BigDecimal updatedTotalRefundAmount, @Param("id") Long id);

    int updateStatusById(@Param("updatedStatus") Byte updatedStatus, @Param("id") Long id);

    int updateStatusAndCompleteTimeById(@Param("updatedStatus") Byte updatedStatus, @Param("updatedCompleteTime") Date updatedCompleteTime, @Param("id") Long id);

    Long countByTimeRange(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    Long countByTimeRangeAndTenantId(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("tenantId") Long tenantId);

    Long countByTenantId(@Param("tenantId") Long tenantId);

    Long countByUserIdAndStatusIn234(@Param("userId") Long userId);

    Long countByStatus(@Param("status") Byte status);

    Long countByStatusAndLogisticsStatus(@Param("status") Byte status);

    Long countByStatusAndLogisticsStatusAndTenantId(@Param("status") Byte status, @Param("tenantId") Long tenantId);

    Long countByStatusAndLogisticsStatusAndTenantIdAndRushBuyStatus(@Param("status") Byte status, @Param("tenantId") Long tenantId, @Param("rushBuyStatus") Byte rushBuyStatus);

    Long countByStatusAndDeliveriesAndTenantId(@Param("status") Byte status, @Param("tenantId") Long tenantId);

    int autoUpdateOrderStatus(@Param("updateStatus") Byte updateStatus, @Param("now") Date now, @Param("status") Byte status, @Param("timeBefore") Date timeBefore);

    int autoUpdateOrderStatusToComment(@Param("updateStatus") Byte updateStatus, @Param("status") Byte status, @Param("logisticsStatus") Byte logisticsStatus, @Param("timeBefore") Date timeBefore);

    int updateCloseReasonAndCloseTimeAndStatusByIdAndUserId(@Param("updatedCloseReason") Integer updatedCloseReason, @Param("updatedCloseTime") Date updatedCloseTime, @Param("updatedStatus") Byte updatedStatus, @Param("id") Long id, @Param("userId") Long userId);

    Orders findOneByRefundNo(@Param("refundNo") String refundNo);

    int deleteByIdAndStatus(@Param("id") Long id, @Param("status") Byte status);

    List<Orders> findAllByOrderTypeAndStatusAndLogisticsStatusAndCreatedAt(@Param("orderType") Byte orderType, @Param("status") Byte status, @Param("createdAt") Date createdAt);

    CountOrderVO countByCreatedAtAndStatus(PageReq req);

    Orders findTopOneByUserIdAndStatus(@Param("userId") Long userId);

    int updateNameAndPhoneByIdAndUserId(@Param("updatedName") String updatedName, @Param("updatedPhone") String updatedPhone, @Param("id") Long id, @Param("userId") Long userId);

    int updateTradeNoById(@Param("updatedTradeNo") String updatedTradeNo, @Param("id") Long id);

    List<Orders> findAllByOrdersIds(@Param("list") List<Long> ordersIds);

    List<Orders> findAllByUserIdAndShopId(@Param("userId") Long userId, @Param("shopId") Long shopId);

    Orders findOneByLogisticsNumber(@Param("logisticsNumber") String logisticsNumber);

    int updateFreezeStatusById(@Param("updatedFreezeStatus") Byte updatedFreezeStatus, @Param("id") Long id);

    OrderStatisticAmountVO countByTimeStart(@Param("dateStart") Date dateStart, @Param("shopId") Long shopId);

    BigDecimal sumAmout(OrderPageReq req);

    List<StatisticsVO> getOrderMonthStatistics(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("shopId") Long shopId);

    BigDecimal sumConsume(Long id);

    BigDecimal sumPageAmount(PageReq req);

    List<StatisticsVO> getOrderStatisticsByYear(@Param("start") Date start, @Param("end") Date end, @Param("shopId") Long shopId);

    BigDecimal sumAmountByTimeRange(@Param("start") Date start, @Param("end") Date end, @Param("shopId") Long shopId);

    BigDecimal sumCompleteAmount(Long shopId);

    OrderDataStatisticsVO getOrderDataStatistics(OrderPageReq req);

    PlatformCommissionAmountVO sumPlatformCommissionAmountByTimeRange(@Param("start") Date start, @Param("end") Date end);

    int updateLogisticsStatusAndLogisticsCompanyAndLogisticsNumberById(@Param("updatedLogisticsStatus") Byte updatedLogisticsStatus, @Param("updatedLogisticsCompany") String updatedLogisticsCompany, @Param("updatedLogisticsNumber") String updatedLogisticsNumber, @Param("id") Long id);

    BigDecimal sumByTimeRangeAndTenantId(@Param("startTime") Date yesterdayStart, @Param("endTime") Date yesterdayEnd, @Param("tenantId") Long tenantId);

    Long countByTimeRangeAndTenantIdAndRefundNoIsNotNull(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("tenantId") Long tenantId);

    @Select("<script>" +
            "select DATE_FORMAT(created_at, '%Y-%m-%d') day,\n" +
            "       COUNT(id) total\n" +
            "from orders\n" +
            "<where>  status in (2,3,4) \n" +
            "<if test=\"startTime != null and startTime != '' and endTime != null and endTime != ''\"> and created_at between #{startTime} and #{endTime} \n </if>" +
            "</where>\n" +
            "group by day\n" +
            "limit 30" +
            "</script>")
    List<LongCountByDateVO> getOrdersCount(CountByTimeReq req);

    @Select("<script>" +
            "select DATE_FORMAT(created_at, '%Y-%m-%d') day,\n" +
            "       SUM(total_pay_amount) total\n" +
            "from orders\n" +
            "<where>  status in (2,3,4) \n" +
            "<if test=\"startTime != null and startTime != '' and endTime != null and endTime != ''\"> and created_at between #{startTime} and #{endTime} \n </if>" +
            "</where>\n" +
            "group by day\n" +
            "limit 30" +
            "</script>")
    List<BigDecimalCountByDateVO> getPayAmountCount(CountByTimeReq req);

    Long countUserByTenantIdAndCreatedAtBetween(@Param("tenantId") Long tenantId, @Param("minCreatedAt") Date minCreatedAt, @Param("maxCreatedAt") Date maxCreatedAt);

    int updateFlagAndRemarkById(Orders orders);

    Long countRefundByTimeRangeAndTenantId(@Param("todayStart") Date todayStart, @Param("date") Date date, @Param("tenantId") Long tenantId);

    List<DividendOrderVO> findStaticDividendOrderPage(TimeRangeReq req);

    int updateRushBuyStatusById(@Param("updatedRushBuyStatus") Byte updatedRushBuyStatus, @Param("id") Long id);

    int updateRushBuyStatusByIdIn(@Param("updatedRushBuyStatus") Byte updatedRushBuyStatus, @Param("idCollection") Collection<Long> idCollection);
}